home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 8: LINUX Games
/
Linux Cubed Series 8 - LINUX Games.iso
/
games
/
video
/
trojka.tgz
/
trojka.tar
/
trojka
/
system.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-20
|
2KB
|
139 lines
/*
* @(#) system.c -- lowlevel system functions for TROJKA
* created: 4.iii.1992 for XENIX/68000
* modified: 16.iv.1992 Maarten added SunOS + HPUX support
* 20.x.1995 Maarten added Linux support
*/
#ifdef HPUX
#include <codelibs/nap.h>
#endif
#ifdef LINUX
#include <termios.h>
#endif
#ifdef XENIX68
#include <sys/types.h>
#include <sys/timeb.h>
#endif
#include <signal.h>
#include <curses.h>
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include "trojka.h"
extern flag curses_installed;
int killkeys(),
quit_prog();
char getkey();
int initcurses();
int catch();
#if XENIX68
struct timeb *tb; /* for delay */
#endif
char getkey() /* get key from keyboard */
{
#if SUNOS | HPUX | LINUX
long count;
char ch;
ioctl(0,FIONREAD,&count); /* check if there's something to read */
if(count > 0)
return(ch = getchar());
return(0);
#endif
#if XENIX68
static char buf[1];
if(rdchk(0)>0) {
read(0,buf,1);
return(buf[0]);
}
#endif
}
int killkeys() /* flush keyboard buffer */
{
fflush(stdin);
}
int initcurses()
{
#ifdef SUNOS
struct sgttyb terminfo;
ioctl(0,TIOCGETP,&terminfo);
#endif
initscr();
crmode();
nonl();
noecho();
signal(SIGTERM, catch);
signal(SIGINT, catch);
curses_installed = TRUE;
#ifdef SUNOS
if (LINES < 24 || COLS < 80)
quit_prog("Sorry. The screensize must be at least 80 x 24");
#endif
}
int catch(sig)
int sig;
{
signal(SIGTERM, SIG_IGN);
signal(SIGINT, SIG_IGN);
quit_prog("See you around in the Trojka-zone...");
}
int quit_prog(s)
char *s;
{
if(curses_installed) {
clear();
refresh();
echo();
nl();
nocrmode();
endwin();
}
fprintf(stderr,"%s\n",s);
exit(0);
}
int delay(millisecs)
int millisecs;
{
#if SUNOS | LINUX
usleep(millisecs * 1200); /* usleep does microsecs; need millisecs */
#endif
#ifdef HPUX
nap(millisecs);
#endif
#if XENIX68
/* believe me, this works */
long goal;
ftime(tb);
goal = (long)(tb->time*(long)1000)+(tb->millitm/40)+(long)(millisec/50);
while((long)(tb->time*(long)1000)+(tb->millitm/40)<goal)
ftime(tb);
#endif
}